import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  strict: true,
  state: {
    Earthlist: [{
        id: "1",
        address: "河北",
        time: "2019-1-14",
        magnitude: 6.5
      },
      {
        id: "2",
        address: "河北",
        time: "2019-1-14",
        magnitude: 6.5
      },    
    ],
  },
  getters: {
    getEarthList: state => {
      return state.Earthlist
    },
    getEarthListItem: state => index => {
      return state.Earthlist[index]
    }
  },
  mutations: {
    addEarthlist: (state, item) => {
      state.Earthlist.push(item)
    },
    UPDataEarthlist: (state, [item,index]) => {
     state.Earthlist.splice(index,1,item)
    },
    RemoveEarthlistItem:(state,index)=>{
      state.Earthlist.splice(index,1)
    }
  },
  actions: {
    addEarthlist({
      commit
    },item) {
        commit('addEarthlist', item)
    },
    UPDataEarthlist({
      commit
    },item) {
        commit('UPDataEarthlist', item)
    },
    RemoveEarthlistItem({
      commit
    },index){
      commit('RemoveEarthlistItem', index)
    }
  }
})